{$define ilasm}
unit toolsb;
interface

Function max(a,b:integer):integer;
Function min(a,b:integer):integer;
Function LongSwap(const number:Longint):Longint;
Function Upcases(s:string):string;
Procedure Orezej(var a:string);


Type Fconv_i=Function(const i:integer):integer;
     Fconv_l=Function(const i:longint):longint;
     xxx=byte;

Function HiEnd2CPU(const i:integer):integer;
Function LoEnd2CPU(const i:integer):integer;
Function HiEnd2CPUl(const i:longint):longint;
Function LoEnd2CPUl(const i:longint):longint;

implementation

{---------Assembler procedures depends on HW 80x86---------}

{$ifdef ilasm}
Function min(a,b:integer):integer; assembler;
asm
	mov	ax,a
	cmp	ax,b
	jl	@konec
	mov	ax,b
@konec:
end;

Function max(a,b:integer):integer; assembler;
asm
	mov	ax,a
	cmp	ax,b
	jg	@konec
	mov	ax,b
@konec:
end;

{$else}
Function min(a,b:integer):integer;
begin
  min:=a;
  if b<a then min:=b;
end;

Function max(a,b:integer):integer;
begin
  max:=a;
  if b>a then max:=b;
end;

{$endif}

Function LongSwap(const number:Longint):Longint;
type  swaptyp = record
	case Boolean of
		True :(x:longint);
		False:(a:array[1..2] of word);
	   end;
var n,r:swaptyp;
begin
 n.x:=number;
 r.a[1]:=swap(n.a[2]);
 r.a[2]:=swap(n.a[1]);
 LongSwap:=r.x;
end;

Function LoEnd2CPU(const i:integer):integer;
begin
 LoEnd2CPU:=i;
end;

Function HiEnd2CPU(const i:integer):integer;
begin
 HiEnd2CPU:=Swap(i);
end;

Function LoEnd2CPUl(const i:longint):longint;
begin
 LoEnd2CPUl:=i;
end;

Function HiEnd2CPUl(const i:longint):longint;
begin
 HiEnd2CPUl:=LongSwap(i);
end;


{prevede retezec na velka pismena}
Function Upcases(s:string):string;
var i:byte;
begin
  for i:=1 to length(s) do s[i]:=UpCase(s[i]);
  Upcases:=s;
end;

Procedure Orezej(var a:string);
begin
 while a[Length(a)]=' ' do dec(a[0]);
 while (a<>'') and (a[1]=' ') do a:=copy(a,2,Length(a));
end;

end.
